<?php
class Training_LocaleController extends Zendvn_Controller_Action{
    
    public function init() {
        parent::init();
        $this->_helper->layout->disableLayout();
        $this->_helper->viewRenderer->setNoRender();
    }
    
    public function indexAction() {
        //vi_VN en_GB en_US en_SG de_DE
//        $locale = new Zend_Locale('vi_VN');
//        echo '<br>' . $locale;
//        $browser = $locale->getBrowser();
//        $tmp     = $locale->getHttpCharset();
//        $locale  = $locale->getLocaleList();
//        $region  = $locale->getRegion();
        $path = 'CurrencyToName';
        $locale = 'vi_VN';
        $value = '1';
        $traslation = Zend_Locale::getTranslationList($path, $locale, $value);
        echo '<pre>';
        print_r($traslation);
        echo '<pre>';
    }
    
    public function index2Action() {
        //vi_VN en_GB en_US en_SG de_DE
        $locale = new Zend_Locale('vi_VN');
        echo '<br>' . $locale;

        $path = 'territory';
        $locale = 'de_DE';
        $value = 'SG';
        $traslation = Zend_Locale::getTranslation($value, $path, $locale);
        echo '<pre>';
        print_r($traslation);
        echo '<pre>';
    }
    
    public function index3Action() {
        //vi_VN en_GB en_US en_SG de_DE
        $locale = new Zend_Locale('vi_VN');
        echo '<br>' . $locale;

        $path = 'territoryToPhone';
        $locale = 'vi_VN';
        $value = '49';
        echo '<br> Ki hieu quoc gia: ' . $traslation = Zend_Locale::getTranslation($value, $path, $locale);
        
        $path = 'territory';
        $value = $traslation;
        echo '<br> Ten quoc gia: ' . $traslation = Zend_Locale::getTranslation($value, $path, $locale);
        echo '<pre>';
        print_r($traslation);
        echo '<pre>';
    }
    
    public function index4Action() {
        //vi_VN en_GB en_US en_SG de_DE
        $locale = new Zend_Locale('vi_VN');
        echo '<br>' . $locale;

        $path = 'NameToCurrency';
        $locale = 'vi_VN';
        $value = 'USD';
        $traslation = Zend_Locale::getTranslation($value, $path, $locale);
        
        echo '<pre>';
        print_r($traslation);
        echo '<pre>';
    }
    
    public function index5Action() {
        $localeList = Zend_Locale::getLocaleList();
        echo '<pre>';
        print_r($localeList);
        echo '<pre>';
    }
    
    public function index6Action() {
        $date = Zend_Locale_Format::getDateFormat('en_US');
        $time = Zend_Locale_Format::getTimeFormat('en_US');
        echo '<pre>';
        print_r($date);
        echo '<pre>';
        echo '<pre>';
        print_r($time);
        echo '<pre>';
    }
    
    public function index7Action() {
        //toNumber() & isNumber()
        $input = 1234567.890123;
        $options = array('locale'=>'en_US');
        $number_1 = Zend_Locale_Format::toNumber($input, $options);
        $options = array('locale'=>'vi_VN');
        $number_2 = Zend_Locale_Format::toNumber($input, $options);
        echo '<pre>';
        print_r($number_1);
        echo '<pre>';
        echo '<pre>';
        print_r($number_2);
        echo '<pre>';
    }
    
    public function index8Action() {
        //toNumber() & isNumber()
        $input = 1234567.890523;
        $options = array(
                         'locale'=>'en_US',
                         'precision'=> 2,
                        );
        $number_1 = Zend_Locale_Format::toNumber($input, $options);
        echo $input . "<br/>" . $number_1;
    }
    
    public function index9Action() {
        //toNumber() & isNumber()
        $input = 1234567000.890523;
        //1,234,567.890  - #,##0.##0
        //1,23,45,67.890  - #,#0.##0
        //12,34,567.890  - #,##,##0.##0
        $options = array(
                         'locale'=>'vi_VN',
//                         'precision'=> 2,
                         'number_format'=> "#,##,##0.##0",
                        );
        $number_1 = Zend_Locale_Format::toNumber($input, $options);
        echo $input . "<br/>" . $number_1;
    }
    
    public function index10Action() {
        //toNumber() & isNumber()
        echo "<br/>" . $input = "1.234.567,890523";
        $options = array('locale'=>'en_GB');
        if(Zend_Locale_Format::toNumber($input, $options)){
            echo "<br/> Dung dinh dang quoc gia";
        }else{
            echo "<br/> không đúng dinh dang quoc gia";
        }
    }
    
    public function index11Action() {
        //getInteger() - toInteger() - isInteger()
        
        echo '<br/>' . $input = 1234567.890523;
        //$number = Zend_Locale_Format::getInteger($input, array('locale'=>"vi_VN"));
        //$number = Zend_Locale_Format::toInteger($input, array('locale'=>"vi_VN"));
        
        $input = 123.45;
        $number = Zend_Locale_Format::isInteger($input, array('locale'=>"vi_VN"));
        echo '<pre>';
        var_dump($number);
        echo '<pre>';
    }
    
    public function index12Action() {
        //getDate() & checkDateFormat()
        
//        $date = '13.04.2006';
//        $options = array('locale'=>'vi_VN');
//        
//        $date = '04.13.2006'; //mm-dd-yyy
//        $options = array('locale'=>'en_US');
        
        $date = '13.04.2006';
        $options = array('locale'=>'en_US', 'date_format'=>'dd.MM.yyyy');
        $arrDate = Zend_Locale_Format::getDate($date, $options);
        echo '<pre>';
        print_r($arrDate);
        echo '<pre>';
        
        $date = '13.04.2006 22:14:33';
        $options = array('locale'=>'vi_VN', 'date_format'=>'dd.MM.yyyy HH:mm:ss');
        $arrDate = Zend_Locale_Format::getDate($date, $options);
        echo '<pre>';
        print_r($arrDate);
        echo '<pre>';
    }
    
    public function index13Action() {
        $date = '13.Apr.2006';
        $options = array('locale'=>'de_AT', 'date_format'=>  Zend_Locale_Format::STANDARD);
        if(Zend_Locale_Format::checkDateFormat($date, $options)){
            echo '<br> OK';
        }else{
            echo '<br> NOT OK';
        }
    }
    
    public function index14Action() {
        $date = '13:44:42';
        $options = array('locale'=>'vi_VN', 'date_format'=>'HH:mm:ss');
        if(Zend_Locale_Format::checkDateFormat($date, $options)){
            echo '<br> OK';
        }else{
            echo '<br> NOT OK';
        }
    }
}
?>